package com.yu.crm.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yu.crm.domain.pojo.Region;
import com.yu.crm.domain.pojo.Ticketinfo;
import com.yu.crm.domain.request.DeviceRequest;
import com.yu.crm.service.impl.TicketinfoService;
import com.yxzz.common.helper.valid.ValidatorHelpers;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zds
 * @since 2021-03-15
 */
@Api(tags = "票务信息管理")
@RestController
@RequestMapping("/ticketinfo")
public class TicketinfoController {

    @Autowired
    private TicketinfoService ticketinfoService;

    @ApiOperation(value = "测试")
    @GetMapping(value = "/test")
    public String test() {
        return "sucess";
    }

    @ApiOperation("根据id批量删除")
    @DeleteMapping("/remove-batch-by-id")
    public void removeBatchById(@RequestParam("ids") String ids) {
        ticketinfoService.deleteByIds(ids);
    }

    @ApiOperation("根据id删除车站")
    @DeleteMapping("/remove-by-id/{id}")
    public void removeById(@PathVariable Long id) {
        ticketinfoService.removeById(id);
    }

    @ApiOperation(value = "查询列表导出用")
    @GetMapping(value = "/pageList")
    public List<Ticketinfo> getPageList(@RequestParam(required = false) String stationName,
                                        @RequestParam(required = false) String condition) {
        return ticketinfoService.getPage(stationName, condition);
    }

    @ApiOperation(value = "查询列表")
    @GetMapping(value = "/page")
    public IPage<Ticketinfo> getPage(Page<Ticketinfo> page,
                                     @RequestParam(required = false) String stationName,
                                     @RequestParam(required = false) String condition) {
        return ticketinfoService.getPage(page, stationName, condition);
    }

    @ApiOperation(value = "通过身份证号查询购票时间")
    @PostMapping(value = "/selectTicket")
    public Integer selectTicket(@RequestBody DeviceRequest deviceRequest) {
        ValidatorHelpers.notEmpty(deviceRequest.getId(), "编号不能为空");
//        ValidatorHelpers.notEmpty(deviceRequest.getType(), "编号类型不能为空");
        ValidatorHelpers.notEmpty(deviceRequest.getDeviceId(), "设备编号不能为空");
        return ticketinfoService.selectTicket(deviceRequest.getId(), deviceRequest.getType(), deviceRequest.getDeviceId());
    }

    @ApiOperation(value = "保存或修改")
    @PostMapping(value = "/save")
    public boolean save(@RequestBody Ticketinfo ticketinfo) {
        return ticketinfoService.addOrUpdate(ticketinfo);
    }

    /**
     * 通过票务信息主键查询票务信息详情
     *
     * @param id 票务信息主键
     * @return
     */
    @ApiOperation(value = "通过票务信息主键查询票务信息详情")
    @GetMapping(value = "/info-by-id")
    public Ticketinfo infoById(@RequestParam("id") Long id) {
        ValidatorHelpers.notEmpty(id, "票务信息编号不能为空");
        return ticketinfoService.infoById(id);
    }

}

